package com.c.ctgproject.ui.collect

import android.view.View
import com.bumptech.glide.Glide
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseActivityV2
import com.c.ctgproject.databinding.ActivityCarInfoBinding
import com.c.ctgproject.entity.guang.CarInfoEntityV2
import com.c.ctgproject.http.ApiMethods
import com.c.ctgproject.http.MyObserverHandlerLoading
import com.c.ctgproject.utils.*
import com.c.ctgproject.wiget.common.CarInfoLayout
import com.c.ctgproject.wiget.dialog.ShowImgVideoFragment

/**
 *作者:LiBW
 *创建日期: 2021/9/8
 *描述:车辆详情 页面 废弃
 */
class CarInfoActivity : BaseActivityV2() {
    private val mBinding by lazy { ActivityCarInfoBinding.inflate(layoutInflater) }
    override fun getLayout() = mBinding.root
    private val mCarId by lazy { intent.getIntExtra(MyConstants.CAR_ID, -1) }
    private var imageUrl = ""
    override fun event() {
        ApiMethods.apiSubscribe(ApiMethods.retrofit.carDetail(mCarId.handlerNull()), MyObserverHandlerLoading(this, loading) {
            MyLog.d("车辆详情回调:$it")
            val entity = getGson().fromJson(it, CarInfoEntityV2::class.java).data
            entity?.let { data ->
                mBinding.mContainer1.addView(CarInfoLayout(this, "制单人", data.createPersonName.noDataHandler()))
                mBinding.mContainer1.addView(CarInfoLayout(this, "收车时间", data.createTime.noDataHandler()))
                mBinding.mContainer1.addView(CarInfoLayout(this, "车辆来源", data.carSource.noDataHandler()))
                val energy = when (data.energy) {
                    1 -> "燃油车"
                    2 -> "电动车"
                    3 -> "油电混合"
                    else -> "暂无数据"
                }
                mBinding.mContainer1.addView(CarInfoLayout(this, "能源类型", energy))
                val hasBattery = when (data.hasBattery) {
                    1 -> "有"
                    0 -> "无"
                    else -> "暂无数据"
                }
                mBinding.mContainer1.addView(CarInfoLayout(this, "有无电池", hasBattery))
                mBinding.mContainer1.addView(CarInfoLayout(this, "车牌号", data.carPlate.noDataHandler()))
                mBinding.mContainer1.addView(CarInfoLayout(this, "VIN码", data.carVin.noDataHandler()))
                mBinding.mContainer1.addView(CarInfoLayout(this, "车型", data.carModel.noDataHandler()))
                val carType = when (data.carType) {
                    1 -> "社会车"
                    2 -> "试验车"
                    3 -> "外包车"
                    4 -> "五类车"
                    5 -> "农机具"
                    else -> "暂无数据"
                }
                mBinding.mContainer1.addView(CarInfoLayout(this, "车辆性质", carType))
                val statue = when (data.carStatus) {
                    1 -> "整车"
                    2 -> "车架"
                    else -> "暂无数据"
                }
                mBinding.mContainer1.addView(CarInfoLayout(this, "车辆状态", statue))
                mBinding.mContainer1.addView(CarInfoLayout(this, "车辆自编码", data.carCode.noDataHandler()))
                mBinding.mContainer1.addView(CarInfoLayout(this, "路桥费", data.toll.noDataHandler()))
                val entrance = when (data.entrance) {
                    1 -> {
                        "已完成"
                    }
                    0 -> {
                        "未完成"
                    }
                    2 -> {
                        "驳回"
                    }
                    else -> "暂无数据"
                }
                mBinding.mContainer2.addView(CarInfoLayout(this, "登记入库", entrance))
                mBinding.mContainer2.addView(CarInfoLayout(this, "过磅", data.pound.finishHandler()))
                mBinding.mContainer2.addView(CarInfoLayout(this, "初检", data.carCheck.finishHandler()))
                mBinding.mContainer2.addView(CarInfoLayout(this, "排油水", data.oilWaterDrainage.finishHandler()))
                mBinding.mContainer2.addView(CarInfoLayout(this, "拆电池", data.batteryDisassemble.finishHandler()))
                mBinding.mContainer2.addView(CarInfoLayout(this, "预处理", data.pretreatment.finishHandler()))
                mBinding.mContainer2.addView(CarInfoLayout(this, "拆解", data.dismantle.finishHandler()))
                val dismantleType = when (data.dismantleType) {
                    1 -> "毁型"
                    2 -> "拆配件"
                    else -> "暂无数据"
                }
                mBinding.mContainer2.addView(CarInfoLayout(this, "拆解方式", dismantleType))

//                //1.燃油车 2.电动车 3.油电混合
//                when (data.energy) {
//                    1 -> {
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "发动机", data.engine.noDataHandler()))
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "变速箱", data.transmissionCase.noDataHandler()))
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "三元催化", data.ternaryCatalysis.noDataHandler()))
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "蓄电池", data.battery.noDataHandler()))
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "动力电池", data.powerBattery.noDataHandler()))
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "耦合电机", data.couplingMotor.noDataHandler()))
//
//                    }
//                    2 -> {
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "发动机", data.engine.noDataHandler()))
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "变速箱", data.transmissionCase.noDataHandler()))
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "三元催化", data.ternaryCatalysis.noDataHandler()))
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "蓄电池", data.battery.noDataHandler()))
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "动力电池", data.powerBattery.noDataHandler()))
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "耦合电机", data.couplingMotor.noDataHandler()))
//                    }
//                    3 -> {
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "发动机", data.engine.noDataHandler()))
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "变速箱", data.transmissionCase.noDataHandler()))
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "三元催化", data.ternaryCatalysis.noDataHandler()))
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "蓄电池", data.battery.noDataHandler()))
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "动力电池", data.powerBattery.noDataHandler()))
//                        mBinding.mContainer3.addView(CarInfoLayout(this, "耦合电机", data.couplingMotor.noDataHandler()))
//                    }
//                    else ->{
//
//                    }
//                }

                mBinding.mContainer3.addView(CarInfoLayout(this, "发动机", data.engine.noDataHandler()))
                mBinding.mContainer3.addView(CarInfoLayout(this, "变速箱", data.transmissionCase.noDataHandler()))
                mBinding.mContainer3.addView(CarInfoLayout(this, "三元催化", data.ternaryCatalysis.noDataHandler()))
                mBinding.mContainer3.addView(CarInfoLayout(this, "蓄电池", data.battery.noDataHandler()))
                mBinding.mContainer3.addView(CarInfoLayout(this, "动力电池", data.powerBattery.noDataHandler()))
                mBinding.mContainer3.addView(CarInfoLayout(this, "耦合电机", data.couplingMotor.noDataHandler()))

//                mBinding.mContainer3.addView(CarInfoLayout(this, "底盘", data.chassis.noDataHandler()))
//                mBinding.mContainer3.addView(CarInfoLayout(this, "发动机", data.engine.noDataHandler()))
//                mBinding.mContainer3.addView(CarInfoLayout(this, "变速箱", data.transmissionCase.noDataHandler()))
//                mBinding.mContainer3.addView(CarInfoLayout(this, "轮毂", data.hub.noDataHandler()))
//                mBinding.mContainer3.addView(CarInfoLayout(this, "轮胎", data.tyre.noDataHandler()))
//                mBinding.mContainer3.addView(CarInfoLayout(this, "三元催化", data.ternaryCatalysis.noDataHandler()))
//                mBinding.mContainer3.addView(CarInfoLayout(this, "蓄电池", data.battery.noDataHandler()))
//                mBinding.mContainer3.addView(CarInfoLayout(this, "动力电池", data.powerBattery.noDataHandler()))
//                mBinding.mContainer3.addView(CarInfoLayout(this, "起动机", data.starter.noDataHandler()))
//                mBinding.mContainer3.addView(CarInfoLayout(this, "发电机", data.alternator.noDataHandler()))
//                mBinding.mContainer3.addView(CarInfoLayout(this, "水箱", data.waterTank.noDataHandler()))
//                mBinding.mContainer3.addView(CarInfoLayout(this, "空调", data.airConditioner.noDataHandler()))
//                mBinding.mContainer3.addView(CarInfoLayout(this, "耦合电机", data.couplingMotor.noDataHandler()))


                mBinding.mContainer4.addView(CarInfoLayout(this, "过磅人", data.poundPersonName.noDataHandler()))
                mBinding.mContainer4.addView(CarInfoLayout(this, "磅单号", data.poundNo.noDataHandler()))
                mBinding.mContainer4.addView(CarInfoLayout(this, "过磅重量KG", data.poundWeight.noDataHandler()))
                mBinding.mContainer4.addView(CarInfoLayout(this, "采购单号", data.purchasePoundNo.noDataHandler()))
                mBinding.mContainer4.addView(CarInfoLayout(this, "采购重量KG", data.purchaseWeight.noDataHandler()))
                mBinding.mContainer4.addView(CarInfoLayout(this, "过磅时间", data.poundTime.noDataHandler()))
                val image = data.poundPicture.handlerNull()
                if (image.isNotEmpty()) {
                    mBinding.mImageViewTV.visibility = View.VISIBLE
                    mBinding.mImageView.visibility = View.VISIBLE
                    Glide.with(this).load(image).error(R.mipmap.app_icon).into(mBinding.mImageView)
                    mBinding.mImageView.setOnClickListener {
                        ShowImgVideoFragment(image).show(supportFragmentManager, "")
                    }
                }
                imageUrl = data.poundPicture.handlerNull()
                mBinding.mContainer5.addView(CarInfoLayout(this, "物流单号", data.logisticsNo.noDataHandler()))
                mBinding.mContainer5.addView(CarInfoLayout(this, "物流公司", data.logisticsCompany.noDataHandler()))
                mBinding.mContainer5.addView(CarInfoLayout(this, "发货地址", data.sendAddress.noDataHandler()))
                mBinding.mContainer5.addView(CarInfoLayout(this, "收货地址", data.receiveAddress.noDataHandler()))
                mBinding.mContainer5.addView(CarInfoLayout(this, "物流车牌", data.logisticsPlate.noDataHandler()))
//                mBinding.mContainer5.addView(CarInfoLayout(this, "路桥费", data.toll.noDataHandler()))
            }
        })
    }


    override fun click() {
        mBinding.mImageView.setOnClickListener {
            if (imageUrl.isNotEmpty()) {
                ShowImgVideoFragment(imageUrl).show(supportFragmentManager, "")
            }
        }
    }
}